package com.test.mvc.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.test.dao.UserDAO;
import com.test.entity.User;
import com.test.utils.SpringContextHolder;

public class HelloWordController implements Controller {

    @Override
    public ModelAndView handleRequest(HttpServletRequest request
            , HttpServletResponse response) throws Exception {
        ModelAndView mv = new ModelAndView("hello");
        mv.addObject("title", "孙波主页");
        mv.addObject("content", " Hello world ， test my first spring mvc ! ");
        //UserDAO userDAO = (UserDAO)SpringContextUtil.getBean("userDAO");
        //UserDAO userDAO = SpringContextHolder.getBean(UserDAO.class);
        UserDAO userDAO = SpringContextHolder.getBean("userDAO");
		List<User> list=userDAO.findList("from User where id = ?",3);
		for(int i=0;i<list.size();i++){
			System.out.println("name="+list.get(i).getNickname()+",passwd="+list.get(i).getPasswd());
		}
		mv.addObject("sunbo",list.get(0).getNickname()+list.get(0).getPasswd());
        return mv;
    }
}